package gcu.module.property_money.controller;

import gcu.module.build.daomain.Build;
import gcu.module.build.service.BuildService;
import gcu.module.owner.service.OwnerService;
import gcu.module.property_money.daomain.PropertyMoney;
import gcu.module.property_money.service.MoneyService;
import gcu.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * Created by haol on 2016/9/25.
 */
@Controller
@RequestMapping("/money")
public class MoneyController {
      @Autowired
      private MoneyService moneyService;
      @Autowired
      private BuildService buildService;

      /**
       * @param model
       * @param id 为业主的id
       * @return
       */
      @RequestMapping("/edit/{id}")
      public String edit(Model model, @PathVariable Integer id) {
            model.addAttribute("ownerId", id);
            return "/money/edit";
      }


      @RequestMapping("/list")
      public String getApplyList(Model model, PropertyMoney apply, Pager pager) {
            List<PropertyMoney> moneys = moneyService.queryMoneyList(apply, pager);
            moneyService.freshenMoney();

            List<Build> build_list = buildService.queryBuild();
            model.addAttribute("build_list",build_list);

            model.addAttribute("moneyList", moneys);
            model.addAttribute("pager", pager);
            return "/money/list";
      }

      @RequestMapping("/freshen")
      public String freshenMoney(){
            moneyService.freshenMoney();
            return "redirect:/money/list";
      }

      @RequestMapping("/del/{id}")
      public String del( @PathVariable Integer id) {
            moneyService.deleteMoney(id);
            return "redirect:/money/list";
      }
}
